# rice_management_project/urls.py
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views as auth_views
from django.shortcuts import render
from django.contrib.auth.decorators import login_required # Import login_required

# Simple placeholder home view accessible only when logged in
@login_required
def home_view(request):
     # Optionally, add context like recent activities, quick links etc.
     return render(request, 'home.html', {'page_title': '仪表盘'})

urlpatterns = [
    path('admin/', admin.site.urls),

    # App URLs
    path('fields/', include('field_management.urls', namespace='field_management')),
    path('planting/', include('planting_records.urls', namespace='planting_records')),
    # Include other app URLs here...
    # path('weather/', include('weather.urls', namespace='weather')),
    # path('community/', include('community.urls', namespace='community')),

    # Authentication URLs using django's built-in views
    path('accounts/login/', auth_views.LoginView.as_view(template_name='registration/login.html'), name='login'),
    path('accounts/logout/', auth_views.LogoutView.as_view(template_name='registration/logged_out.html'), name='logout'),
    # Add other auth views if needed (Password Reset, Change, etc.)
    # path('accounts/', include('django.contrib.auth.urls')), # Includes more auth URLs

    # Home Page URL
    path('', home_view, name='home'),

]

# --- Static files config for Development ---
from django.conf import settings
from django.conf.urls.static import static

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    # If using MEDIA_ROOT for user uploads:
    # urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# --- End Static files config ---